﻿using System.Threading;

namespace Sendmail.Server
{
    public class SmtpServerWorker
    {
        #region Variables
        private readonly SmtpServer _smtpServerMaster;
        #endregion


        #region Constructor
        public SmtpServerWorker(SmtpServer smtpServer)
        {
            _smtpServerMaster = smtpServer;
        }
        #endregion

        #region Run
        public void Run()
        {
            while (_smtpServerMaster.ServerIsWorking && _smtpServerMaster.ServerListenerIsWorking)
            {
                var handler = new Connection(_smtpServerMaster, _smtpServerMaster.Listener.AcceptTcpClient(), _smtpServerMaster.CurrentConnectionId);
                //var thread = new Thread(handler.Run);
                //thread.Start();
                ThreadPool.QueueUserWorkItem(handler.Run);
            }
        }
        #endregion
    }
}
